<?php 
/**
 * Display Shifts Offered function
 *
 * Provides Employees Shift Information
 *
 * @author Manas Kalucha <manaskalucha@gmail.com>
 */
include_once 'UTcheckAuth.php';
include_once 'UTerrorcode.php';
include_once 'UTDBGlobal.php';

function displayShiftsOffered($userName,$userPass)
{
	global $dbaddress;
    global $dbuser;
    global $dbpassword;
    global $dbdatabasename;

	if (checkAuthentication($userName, $userPass)==true){
	
		$conn = mysqli_connect($dbaddress,$dbuser,$dbpassword,$dbdatabasename);
		$sql = "SELECT rd.*, r.*, d.* FROM roledate rd, dates d, roles r WHERE r.roleID = rd.roleID AND d.dateID = rd.dateID";
		$result = mysqli_query($conn, $sql);
		
		$ReturnArray = array();
		
		if($result->num_rows>0){
			$error = ErrorCode::successRead;
			$ReturnArray[0] = $error;
			while($row = $result->fetch_assoc()){
				$HoldDataArray = array();
				$HoldDataArray['roleID'] = $row['roleID'];
				$HoldDataArray['dateID'] = $row['dateID'];
				$HoldDataArray['datestamp'] = $row['datestamp'];
				$HoldDataArray['startTime'] = $row['startTime'];
				$HoldDataArray['endTime'] = $row['endTime'];
				$HoldDataArray['roleName'] = $row['roleName'];
				$ReturnArray[count($ReturnArray)] = $HoldDataArray;
			}
		}
	} else {
		$error = ErrorCode::authFailRead;
		$ReturnArray  = array($error);
	}
	return $ReturnArray;	
}

?>
